require("zq_function")
local sz = require("sz")

local json = sz.json
local w,h = getScreenSize();

MyTable = {
	["style"] = "default",
	["width"] = w,
    ["height"] = h,
	["cancelname"] = "取消", 
	["okname"] = "开始",
	views = {
		 {
            ["type"] = "Label",
            ["text"] = "关卡人物(可多选,至少选1个)",
            ["size"] = 12,
            ["align"] = "left",
            ["color"] = "0,0,255",
        },
		{
			["type"] = "CheckBoxGroup",                       --下拉框，input4
			["list"] = "卢植,徐庶,张绣1,典韦1,刘备,公孙瓒,关羽,孙坚,高顺,何进,曹洪,曹操,张飞2,乐进,徐晃1,贾诩1,丁奉,杨奉,孙策1,荀彧,许褚,张辽",
			--7个下拉选项，序号从0开始，即选项1编号为0，选项2编号为1，依此类推
            ["select"] = "0",                       --默认选择选项1
		},
		{
            ["type"] = "Label",
            ["text"] = "出战人所在的位置(可多选,至少选1个)",
            ["size"] = 12,
            ["align"] = "left",
            ["color"] = "0,0,255",
        },
		{
			["type"] = "CheckBoxGroup",                       --下拉框，input4
			["list"] = "1,2,3,4,5,6,7,8,9",
			--7个下拉选项，序号从0开始，即选项1编号为0，选项2编号为1，依此类推
            ["select"] = "0",                       --默认选择选项1
		},
		{
            ["type"] = "Label",
            ["text"] = "备注：本脚本不收费,但触动精灵分免费版、收费版,免费只能运行30分钟左右,实测为70分钟左右,所以免费版关卡别选择太多。当前版本为v1.9.1,使用教程:http://www.jianshu.com/p/8dda94809510,版本代码：https://gitee.com/wolfdong7/zhanqi",
            ["size"] = 18,
            ["align"] = "left",
            ["color"] = "0,0,255",
        },
		
	}
}

local MyJsonString = json.encode(MyTable);

function Split(szFullString, szSeparator) 	
	local nFindStartIndex = 1    
	local nSplitIndex = 1    
	local nSplitArray = {}    
	while true do    
	   local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)    
	   if not nFindLastIndex then    
		nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))    
		break    
	   end    
	   nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)    
	   nFindStartIndex = nFindLastIndex + string.len(szSeparator)    
	   nSplitIndex = nSplitIndex + 1    
	end    
	return nSplitArray    
end 

--[[
	--卢植,徐庶,张绣,典韦,刘备,公孙瓒,关羽,
	孙坚,高顺,何进,曹洪,曹操,张飞,乐进,
	徐晃,贾诩,丁奉,杨奉
	]]
local fight_hero = {	
	[1] = "卢植",[2] = "徐庶",[3] = "张绣",[4] = "典韦",[5] = "刘备",[6] = "公孙瓒",[7] = "关羽",
	[8] = "孙坚",[9] = "高顺",[10] = "何进",[11] = "曹洪",[12] = "曹操",[13] = "张飞",[14] = "乐进",
	[15] = "徐晃",[16] = "贾诩",[17] = "丁奉",[18] = "杨奉",[19] = "孙策",[20] = "荀彧",[21] = "许褚",
	[22] = "张辽"
};
local fight_city = {
	[1] = "颖川",[2] = "颖川",[3] = "宛城",[4] = "宛城",[5] = "宛城",[6] = "虎牢关",[7] = "已水关",
	[8] = "已水关",[9] = "舞阳",[10] = "洛阳",[11] = "荣阳",[12] = "许昌",[13] = "虎牢关",[14] = "官渡",
	[15] = "河东",[16] = "长安",[17] = "安丰",[18] = "弘农",[19] = "江夏",[20] = "郾城",[21] = "定陶",
	[22] = "下肧"
}

function zhanqi_ui()
	local ret,a,b = showUI(MyJsonString);
	local list = Split(a,"@");
	local list_hero = Split(b,"@");
	local count_table = 0;
	
	local i = 0;
	local result_function;
	local result_number;
	for k,v in pairs(list) do  
		count_table = count_table + 1  
	end  
	
	mSleep(1000)	
	
	
	for i=1,count_table,1 do
		kaishua(list_hero,fight_city[list[i]+1],fight_hero[list[i]+1]);		
		mSleep(1000)
		
	end
	
	
	nLog("任务完成")
end








